package com.bamboowind.rabbitmq.topic.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ的topic模式的配置类
 *
 * @author cpw
 */
@Configuration
public class RabbitConfigTopic {
    /**
     * 创建队列topic_queue
     *
     * @return
     */
    @Bean
    public Queue topicQueue() {
        return new Queue("topic_queue");
    }

    /**
     * 创建队列topic_queue2
     *
     * @return
     */
    @Bean
    public Queue topicQueue2() {
        return new Queue("topic_queue2");
    }

    /**
     * 创建topic模式下的交换机topic_exchange
     *
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topic_exchange");
    }

    /**
     * 将队列topic_queue与交换机topic_exchange进行绑定,routingKey为 topic.*.id
     *
     * @return
     */
    @Bean
    public Binding bindingTopicQueue() {
        return BindingBuilder.bind(topicQueue()).to(topicExchange()).with("topic.*.id");
    }

    /**
     * 将队列topic_queue2与交换机topic_exchange进行绑定,routingKey为 topic.orders.*
     *
     * @return
     */
    @Bean
    public Binding bindingTopicQueue2() {
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("topic.orders.*");
    }
}
